//
//  GuideViewController.m
//  ITrip
//
//  Created by dllo on 15/6/4.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "GuideViewController.h"


@interface GuideViewController ()

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createMyView];
    
}

- (void)createMyView
{
    myscroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    myscroll.delegate = self;
    
    UIImage *image1 = [UIImage imageNamed:@"image-1"];
    imageview1 = [[UIImageView alloc]initWithImage:image1];
    imageview1.frame = self.view.bounds;
    [self.view addSubview:imageview1];
    
    UIImage *image2 = [UIImage imageNamed:@"image-2"];
    imageview2 = [[UIImageView alloc]initWithImage:image2];
    imageview2.frame = self.view.bounds;
    [self.view addSubview:imageview2];
    
    UIImage *image3 = [UIImage imageNamed:@"image-0"];
    imageview3 = [[UIImageView alloc]initWithImage:image3];
    imageview3.frame = self.view.bounds;
    [self.view addSubview:imageview3];
    
    imageview1.alpha = 0;     
    imageview2.alpha = 0;
    imageview3.alpha = 1;
    
    [self.view addSubview:myscroll];
    
    for (int i = 0; i < 3; i++) {
        NSString *str = [NSString stringWithFormat:@"image-%d", i];
        UIImage *iamge = [UIImage imageNamed:str];
        UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageview.image = iamge;
        imageview.alpha = 0.3;
        [myscroll addSubview:imageview];
    }
    
    myscroll.pagingEnabled = YES;
    myscroll.showsHorizontalScrollIndicator = NO;
    myscroll.showsVerticalScrollIndicator = NO;
    myscroll.bounces = NO;
    myscroll.contentSize = CGSizeMake(self.view.frame.size.width * 3, self.view.frame.size.height);
    [myscroll setContentOffset:CGPointMake(0, 0)];
    
    myPage = [[UIPageControl alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 30, self.view.frame.size.height - 80, 60, 40)];
    myPage.backgroundColor = [UIColor clearColor];
    [self.view addSubview:myPage];
    
    myPage.numberOfPages = 3;
    myPage.currentPage = 0;
    myPage.currentPageIndicatorTintColor = [UIColor whiteColor];
    myPage.pageIndicatorTintColor = [UIColor grayColor];
    [myPage addTarget:self action:@selector(touchMe:) forControlEvents:UIControlEventValueChanged];
    
    myButton = [UIButton buttonWithType:UIButtonTypeCustom];
    myButton.backgroundColor = [UIColor clearColor];
    [myButton setTitle:@"即刻寻找幸福" forState:UIControlStateNormal];
    [myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [myButton setFrame:CGRectMake((self.view.frame.size.width * 2) + self.view.frame.size.width / 2 - 80, self.view.frame.size.height - 105, 160, 35)];
    [myButton addTarget:self action:@selector(touchButton:) forControlEvents:UIControlEventTouchUpInside];
    [myscroll addSubview:myButton];
    myButton.layer.cornerRadius = 10;
    myButton.layer.borderColor = [UIColor whiteColor].CGColor;
    myButton.layer.borderWidth = 1;
    
    self.myLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(50, 500, 200, 40)];
    self.myLabel1.backgroundColor = [UIColor clearColor];
    self.myLabel1.text = @"世界那么大";
    self.myLabel1.font = [UIFont systemFontOfSize:20];
    self.myLabel1.textColor = [UIColor whiteColor];
    [myscroll addSubview:self.myLabel1];
    
    self.myLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width + 50, 500, 200, 40)];
    self.myLabel2.backgroundColor = [UIColor clearColor];
    self.myLabel2.text = @"我想去看看";
    self.myLabel2.font = [UIFont systemFontOfSize:20];
    self.myLabel2.textColor = [UIColor whiteColor];
    [myscroll addSubview:self.myLabel2];
    
    self.myLabel3 = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width * 2 + 50, 500, 200, 40)];
    self.myLabel3.backgroundColor = [UIColor clearColor];
    self.myLabel3.text = @"";
    self.myLabel3.font = [UIFont systemFontOfSize:20];
    self.myLabel3.textColor = [UIColor whiteColor];
    [myscroll addSubview:self.myLabel3];
}


- (void)touchMe:(UIPageControl *)page
{
    NSInteger i = myPage.currentPage;
    [myscroll setContentOffset:CGPointMake(self.view.frame.size.width * i, 0) animated:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger i = scrollView.contentOffset.x / self.view.frame.size.width;
    myPage.currentPage = i;
    
    if (scrollView.contentOffset.x > 0 && scrollView.contentOffset.x < self.view.frame.size.width) {
        imageview3.alpha = 1 - ((scrollView.contentOffset.x - i * self.view.frame.size.width) / self.view.frame.size.width);
        imageview1.alpha = (scrollView.contentOffset.x - i * self.view.frame.size.width) / self.view.frame.size.width;
    } if (scrollView.contentOffset.x > self.view.frame.size.width && scrollView.contentOffset.x < self.view.frame.size.width * 2) {
        imageview1.alpha = 1 - ((scrollView.contentOffset.x - i * self.view.frame.size.width) / self.view.frame.size.width);
        imageview2.alpha = (scrollView.contentOffset.x - i * self.view.frame.size.width) / self.view.frame.size.width;
    }
}

- (void)touchButton:(UIButton *)button
{
    [self.delegate show];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
